<?php include 'header.php'; ?>
<?php include 'connect.php'; ?>

<?php
if ( isset($_POST['wf-Check']) && $_POST['wf-Check'] != "" )
{
	$erreur = "<span class='red'>Il ne faut pas remplir le dernier champ !! C'est un filtre anti-spam....</span>";
}

else if ( isset($_POST['wf-Username']) && isset($_POST['wf-Password']) && isset($_POST['wf-Password2']) && isset($_POST['wf-Email']))
{
	if($_POST['wf-Password'] != $_POST['wf-Password2'])
	{
		$erreur = "<span class='red'>Les mots de passe ne correspondent pas</span>";
	}
	else 
	{
		
		$username = $_POST['wf-Username'];
		$sql = "SELECT user_name FROM $table_name 
			  WHERE user_name='$username'";
		$result = mysql_query($sql,$db);
		$num = mysql_fetch_row($result);
		
		$email = $_POST['wf-Email'];
		$sql2 = "SELECT email FROM $table_name 
			  WHERE email='$email'";
		$result2 = mysql_query($sql,$db);
		$num2 = mysql_fetch_row($result);

		if ( $num > 0 )
		{
			$erreur = "<span class='red'>Ce pseudo existe d&eacute;j&agrave;, veuillez en choisir un autre</span>";
		}
		else if (!preg_match('/^[a-z0-9]+$/', $username)) 
		{
		  $erreur = "<span class='red'>Votre pseudo ne doit contenir que des lettres ou des chiffres</span>";
	    }
		else if ( $num2 > 0 )
		{
			$erreur = "<span class='red'>Ce mail existe d&eacute;j&agrave; dans notre base de donn&eacute;e.</span>";
		}
		
		else 
		{
			$sql = ("INSERT INTO ".$table_name." VALUES(
			'', 
			'".mysql_real_escape_string($_POST['wf-Username'])."', 
			'".mysql_real_escape_string(date('Y-m-d'))."',
			'".mysql_real_escape_string(md5($_POST['wf-Password']))."',
			'','','','','','".mysql_real_escape_string($_POST['wf-Email'])."','','','','1','','','".mysql_real_escape_string(date('Y-m-d'))."','','1','','','','','1','','1','','',''
			)");
			mysql_query($sql,$db) or die('Une erreur est survenue: '.mysql_error());
			
			$message = '
			<html>
			
			<head>
    			   <title>Calendrier des anniversaires pour Août</title>
  			</head>
<body>
       <p>Bienvenue sur '.$_GLOBALS[site_name].'</p>
	<p>Votre pseudo est '.$_POST["wf_Username"].'</p>      
 </body>
     </html>
     ';
$headers  = 'MIME-Version: 1.0' . "\r\n";
     $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($_POST['wf_Email'], 'Mail de  confirmation', $message);
			$erreur = "<span class='green'>Un mail de confirmation vous a &eacute;t&eacute; envoy&eacute; contenant votre identifiant.</span>";
		}

	}
}
else 
{
	
}

?>

<div id="teaser">
	  </div>
<script type="text/javascript">
	//<![CDATA[
	$(document).ready(function(){
		$(".hideAlert").hide();
		if($(".hideAlert").html() != ""){$(".hideAlert").show('slow')}
		
		$(".secondaryAction").click(function(){
			$("input:text,input:password").each(function(){
					$(this).val('');});
		});
		$(function(){
		  Attach();
		});
   
		function Attach(){
		  var options = {
			imgsPath: 'images/',
			outsideElt: '#meter'
		  };    
		  $('input#wf-Password').attachPassMeter(options);   
		  return true;
		}

	}); 
	//]]>

</script>
	  <div id="main">

		<div id="gauche">
			<div class="nothing">
				<?php include 'sidebar.php'; ?>
			</div>
		</div>

		<div id="droite">
			<div class="nothing">
				<div class="subcolumns">
					<div class="c33l">
						<div class="subcl">
							<div class="ylert">
								<strong>Pourquoi ?</strong>
								<p>En vous inscrivant, vous obtenez la possibilit&eacute; de g&eacute;rer online votre cv, et ceci gratuitement.</p>
								
								<strong>De nombreux formats:</strong>
								<p>Plus besoin de garder sur vous de nombreux fichiers, pas forc&eacute;ment &agrave; jour. 
								En un seul clic, vous t&eacute;l&eacute;chargez votre CV, dans le format que vous d&eacute;sirez</p>
								
								<strong>Simple et rapide:</strong>
								<p>Pas plus de 2 minutes pour l'inscription. Inscrivez votre pseudo et votre mot de passe, et le tour est jou&eacute;.
						Vous n'aurez qu'&agrave; compl&eacute;ter votre profil une fois enregistr&eacute;.<br/>
						Une fois la v&eacute;rification effectu&eacute;e, vous recevrez un mail de confirmation, contenant votre login et mot de passe. </p>

							</div>

						</div>
					</div>

					<div class="c66r">
						<div class="subcr gr-color">
						
						<div class="ylert bold hideAlert"><?php if(isset($erreur)){echo $erreur; } ?></div>
							
						<form method="post" id="signIn" name="signIn" action="<?php echo $_SERVER['PHP_SELF']?>">

						<span class="oneField"><div class="field-hint-inactive" id="wf-Username-H"><div>Uniquement alpha-num&eacute;riques</div></div>
						<label for="wf-Username" class="preField">Login:</label>
						<input type="text" id="wf-Username" name="wf-Username" value="" size="" class="required validate-alphanum">
						<span class="reqMark">*</span><br></span>
   
						<span class="oneField"><div class="field-hint-inactive" id="wf-Password-H"><div>> &agrave; 8 caract&egrave;res alpha-num&eacute;riques</div></div>
						<label for="wf-Password" class="preField">Mot-de-passe:</label>
						<input type="password" id="wf-Password" name="wf-Password" value="" size="" class="required validate-alphanum validate-strongpassword">
						<span id="meter"></span><span class="reqMark">*</span><br></span>
   
						<span class="oneField"><div class="field-hint-inactive" id="wf-Password2-H"><div>Retapez exactement votre mot de passe</div></div>
						<label for="wf-Password2" class="preField">Retapez le m-d-p:</label>
						<input type="password" id="wf-Password2" name="wf-Password2" value="" size="" class="required validate-alphanum">
						<span class="reqMark">*</span><br></span>
   
						<span class="oneField"><div class="field-hint-inactive" id="wf-Email-H"><div>V&eacute;rifiez votre dossier spam si vous ne recevez pas votre mail</div></div>
						<label for="wf-Email" class="preField">Email:</label>
						<input type="text" id="wf-Email" name="wf-Email" value="" size="" class="required validate-email">
						<span class="reqMark">*</span><br></span>
						
						<label for="wf-Email" class="Uuu">Ne pas remplir:</label><input type="text" name="wf-Check" value="" class="Uuu"/>
						
						<div class="actions">
						
						<input type="submit" class="primaryAction" id="submit-wf_TestForm" value="submit">
						<input type="button" class="secondaryAction" value="cancel">
						</div>
						</form>

						</div>
					</div>
				</div>
			</div>
		</div>

<? include 'footer.php'; ?>
